package cc.fs.kotlinproject

import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Bundle
import android.os.Message
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import butterknife.bindView
import cc.fs.kotlinproject.utlis.Event
import cc.fs.kotlinproject.utlis.e
import cc.fs.kotlinproject.utlis.show
import rx.Observable
import rx.subjects.BehaviorSubject

/**
 * Created by fostion on 2015/8/13.
 */
class LoginActivity : BaseActivity() {

    val button: Button by bindView(R.id.button)
    val account: EditText by bindView(R.id.account)
    val password: EditText by bindView(R.id.password)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)

        val accountObservable = Event.textEvent(account)
        val passwordObservable = Event.textEvent(password)

        runDelay({show(this,"abckde")},2000)

        Observable.combineLatest(accountObservable, passwordObservable, { s1, s2 -> s1 != "" && s2.length() > 3 })
                .subscribe {
                    button.setClickable(it)
                }

        button.setOnClickListener {
            show(this,"show kotlin")
            e("something different")
            MainActivity.start(this)
        }

    }

    override fun handler(message: Message) {
        show(this," LoginActivity  brocast")
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        show(this," $resultCode")
        super.onActivityResult(requestCode, resultCode, data)
    }
}